var map;

function gmap_init(lat,lng,css_id,zoom_level,title){
			var central_point_latlng = new google.maps.LatLng(lat,lng);
    	    var myOptions = {
					zoom: zoom_level,
					center: central_point_latlng,
					mapTypeId: google.maps.MapTypeId.ROADMAP
					};
			map = new google.maps.Map(document.getElementById(css_id),myOptions);
			if (title){
				placeMarker(central_point_latlng,title,'');
			}
}

function placeMarker(location,title,css_id) {  
		var marker = new google.maps.Marker(
				{      
					position: location,       
					map: map,
					draggable:true
				});  
		if (title) marker.setTitle(title);
		if (css_id){
		var infowindow = new google.maps.InfoWindow(
				 {
					 content: jQuery('#'+css_id).html(),
					 maxWidth:780
				 });
		}
		google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker);});
	//	google.maps.event.addListener(marker, 'mouseout', function() { infowindow.close(map,marker);});
}

function add_marker(lat,lng,title,css_id){
	var central_point_latlng = new google.maps.LatLng(lat,lng);
	placeMarker(central_point_latlng,title,css_id);
}

function gmap_init_with_geocode(central_point_postcode,css_id,zoom_level){
	geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': central_point_postcode}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
        
    	    var myOptions = {
					zoom: zoom_level,
					center: results[0].geometry.location,
					mapTypeId: google.maps.MapTypeId.ROADMAP
					};
				map = new google.maps.Map(document.getElementById(css_id),myOptions);
		    var marker = new google.maps.Marker({
   		            map: map, 
   		            position: results[0].geometry.location
   		        });
    	
          }
        else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {    
            setTimeout(function() {
            	gmap_init_with_geocode(central_point_postcode,css_id,zoom_level);
            }, 200);
        } 
        else       alert(marker_postcode + status);
    });

}

function add_marker_with_geocode(marker_postcode){
	geocoder = new google.maps.Geocoder();
    geocoder.geocode( { 'address': marker_postcode}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {	        
		    var marker = new google.maps.Marker({
   		            map: map, 
   		            position: results[0].geometry.location
   		        });
    	
          }
        else if (status === google.maps.GeocoderStatus.OVER_QUERY_LIMIT) {    
            setTimeout(function() {
            	add_marker_with_geocode(marker_postcode);
            }, 200);
        } 
        else       alert(marker_postcode + status);
    });

}